
document.write("<script type='text/javascript' src='js/jquery-2.0.0.js'></script>");
document.write("<script type='text/javascript'  src='layer/layer.js'></script>");
document.write("<script type='text/javascript' src='layer/extend/layer.ext.js'></script>");
$(document).ready(function(){
	$("#contacts").click(function(){
		//location.href ='Customer.jsp';
		$(".kuang3").html("<div class='d1'></div><div class='tou1'></div><div class='tou2'></div><br><div class='tou3'></div>" );
	    $(".d1").append("<p class='font'>当前位置：客户联系人</p>");
	    $(".tou3").html("<h style='color:#3786c7;font-weight:blod; font-size:16px'>总共有<h id='number'></h>条数据,每页显示5条数据</h>&nbsp;<input type='button' value='上一页'   onClick='projectshangyiye1()' class='jihuabutton'>&nbsp<h id='page'>1</h>&nbsp<input type='button' value='下一页' onClick='projectxiayiye1()'  class='jihuabutton'>");
	    $.ajax({
        	type:'post',
			data:'',
			async:false,
			url:"customers.do",
			dataType:'json',
			success:function(data){
				$(".tou1").append("<div class='contacts_zjanniu' id='con_zj'>添加联系人</div><h class='select'>选择客户:</h><select class='projectselect' onChange='contacts1()' name='customer' id='customer'></select><input class='sousuo' type='text'><div class='sousuobutton'>搜索</div>");	 
				for(var i=0;i<data.length;i++){
					$("#customer").append("<option>"+data[i].customerName+"</option>");	
				}
	
	  
	    //$("#xiangmu1").show();
	    
	    
	    
	    
	    
	    
		 $("#con_zj").click(function(){
			 layer.open({
					type:1,
					skin:'layui-layer-demo',
					area:['1000px','200px'],
					shadeClose:true,
					content:'<form id="zengjia111" method="post">'
						+'<center ><table><tr>'
//						+'		<th style="width: 20px; height:35px;">客户Id</th>'
						+'		<th style="width: 20px; height:35px;">联系人姓名</th>'
				        +'		<th style="width: 20px; height:35px;">联系人方式</th>'
				        +'		<th style="width: 20px; height:35px;">创建时间</th></tr>'
				        +'	<tr>'
//				        +'      <td><input type="text" name="contactsId" readonly/></td>'
				        +'      <input type="hidden" value='+$("#customer").val()+' name ="customet"  >'
				        +'      <td><input type="text" name="contactsName" id="contactsName" /></td>'
				        +'      <td><input type="text" name="contactsPhone" id="contactsPhone" /></td>'
				        +'      <td><input type="text" name="createTime" readonly /></td></tr></table>'
				        +'<br><input type="button"  onClick="contactszj_xm()"  value="确认"  id="anniu" name="确认" $nbsp,$nbsp/></center>'
				        +'</form>'
				        
				        
			 });
		 });
			}
	    });
	    project1();
});
	});
function project1(){
	projectpage1();
	$("#page").html("1");
	projectselect1();
//	alert("111");
}
function projectpage1(){
	 $.ajax({
     	type:'post',
			data:{"customer":$("#customer").val()},
			async:false,
			url:"contactspage.do",
			dataType:'json',
			success:function(data){
				$("#number").html(data.num);
			}
			});
}

function contacts1(){
	projectpage1();
	$("#page").html("1");
	projectselect1();
}


function projectshangyiye1(){
	var page=$("#page").html();
	if(page==1){
		alert("已经是第一页了");
	}
	else{
		page=page-1;
		$("#page").html(page);
		projectselect1();
	}
}
function projectxiayiye1(){
	var page=$("#page").html();
	var number=$("#number").html();
	var zong= parseInt(number/5);
    if(!(number%5)){
	}else{
	zong++;
	}
	if(page==zong){
		alert("已经是最后一页了");
	}
	else{
		page++;
		$("#page").html(page);
		projectselect1();
	}
}
function projectselect1(){
//	alert($("#customer").val());
		$.ajax({
			type:'post',
			data:{"userId":$("#page").html(),"customer":$("#customer").val()},
			dataType:'json',
			url:"contacts.do",
			success:function(data){
				
					if(data.length==0){
						$(".tou2").html("暂无记录");
					}
					else{$(".tou2").html("");
					$(".tou2").append("<table class='hovertable' style='width:840px'>");
					
					$(".tou2").append("<tr>"
//					        +"      <th scope='col' style='width: 250px; '><center>客户id</center></th>"
					        +"		<th scope='col' style='width: 250px; '><center>联系人名字</center></th>"
					        +"		<th scope='col' style='width: 100px; '><center>联系人方式</center></th>"
					        +"		<th scope='col' style='width: 250px; '><center>创建时间</center></th>"
					        +"		<th scope='col' style='width: 100px; '><center>修改</center></th>"
					        +"		<th scope='col' style='width: 100px; '><center>删除</center></th>"
					        +"   </tr>");
					 for(var i=0;i<data.length;i++){ 
						 $(".tou2").append("<tr>"
//							        +"       <td class='row' id='type'><center>"+data[i].contactsId+"</center></td>"
							        +"        <td class='row' id='name'><center>"+data[i].contactsName+"</center></td>"
							        +"        <td class='row' id='status'><center>"+data[i].contactsPhone+"</center></td>"
							        +"        <td class='row' id='time'><center>"+data[i].createTime+"</center></td>"
							        +"       <td class='row' id='"+i+"' name='xiugai'><center><img src='images/mod.gif'></center></td>"
							        +"        <td class='row' id='"+i+"' name='shanchu'><center><img src='images/del.gif'></center></td>"
							        +"    </tr>");
							 }
					 $(".tou2").append("</table>");
					 
					 $(".tou2").append("<div style='height:15px'></div>");
					 $("td[name='shanchu']").click(function(){
						 var id=this.id;
						 layer.open({
							 type:1,
							 skin:'layui-layer-demo',
							 area:['1000px','200px'],
							 shadeClose:true,
								content:'<form id="shanchu111" method="post">'
									+'<center id="xiugaiId"><table><tr>'
									+'		<th style="width: 20px; height:35px;"><center>联系人ID</center></th>'
									+'		<th style="width: 20px; height:35px;">联系人名字</th>'
									+'		<th style="width: 20px; height:35px;">联系人方式</th>'
//							        +'		<th style="width: 20px; height:35px;">项目状态</th>'
							        +'		<th style="width: 20px; height:35px;">创建时间</th></tr>'
							        +'	<tr>'
							        +'      <td><input type="text" name="contactsId" value="'+data[id].contactsId+'"/ readonly></td>'
							        +'      <td><input type="text" name="contactsName" value="'+data[id].contactsName+'" readonly/></td>'
							        +'      <td><input type="text" name="contactsPhone" value="'+data[id].contactsPhone+'" readonly/></td>'
//							        +'      <td><input type="text" name="projectStatus" value="'+data[id].projectStatus+'" readonly/></td>'
							        +'      <td><input type="text" name="createTime" value="'+data[id].createTime+'" readonly/></td></tr></table>'
							        +'<br><input type="button" value="确认" onClick="contactssc_xm()" id="anniu" name="确认" $nbsp,$nbsp/></center>'
							        +'</form>'
						 });
					 });
					 
					 $("td[name='xiugai']").click(function(){
						 var id = this.id;
							layer.open({
								type:1,
								skin:'layui-layer-demo',
								area:['1000px','200px'],
								shadeClose:true,
								content:'<form id="xiugai111" method="post">'
									+'<center id="xiugaiId"><table id="tb1"><tr>'
									+'		<th style="width: 20px; height:25px;">联系人Id</th>'
									+'		<th style="width: 20px; height:25px;">联系人名字</th>'
									+'		<th style="width: 20px; height:25px;">联系人方式</th>'
									+'		<th style="width: 20px; height:25px;">创建时间</th>'
							        +'	<tr>'
							        +'      <td><input type="text" name="contactsId" value="'+data[id].contactsId+'"/ readonly></td>'
							        +'      <td><input type="text" name="contactsName" value="'+data[id].contactsName+'"/></td>'
							        +'      <td><input type="text" name="contactsPhone" value="'+data[id].contactsPhone+'"/></td>'
							        +'      <td><input type="text" name="createTime" value="'+data[id].createTime+'"readonly/></td>'
							        +'</tr></table>'
							        +'<br><input type="button" value="确认" onClick="contactsxg_xm()" id="anniu" /></center>'
							        +'</form>'
								});
						});
					}
				}
				
				
			
				});
//		$("#version").css("background","#27a2e6");
		event.stopPropagation();	
}
function contactszj_xm(){
	   var contactsName=$("#contactsName").val();
	   var contactsPhone=$("#contactsPhone").val();
	if(contactsName==""||contactsPhone==""){
		alert("名字和联系方式不能为空");
	}else{
		$.ajax({
			type:'post',
			data:$("#zengjia111").serialize(),
			dataType:'json',
			url:"contacts_zj.do",
			success:function(data){
//				alert("1");
				
				layer.closeAll();
				projectpage1();
				projectselect1();	
			}
		});
	}
		

		
	}
function contactsxg_xm(){
	$.ajax({
		type:'post',
		data:$("#xiugai111").serialize(),
		dataType:'json',
		url:"contacts_xg.do",
		success:function(data){
//			alert("1");
			layer.closeAll();
			projectpage1();
			projectselect1();
		}
	});
}
function contactssc_xm(){
	$.ajax({
		type:'post',
		data:$("#shanchu111").serialize(),
		dataType:'json',
		url:"contacts_sc.do",
		success:function(data){
//			alert("1");
			layer.closeAll();
			projectpage1();
			projectselect1();
		}
	});
}